using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace HostWpfApp.Services;

public class CheckUpdateService : BackgroundService
{
    private readonly ILogger<CheckUpdateService> _logger;

    //虽然把host里面的log替换为了serilog，但是这里的代码不需要改，仍然是微软的logg的使用方法
    public CheckUpdateService(ILogger<CheckUpdateService> logger)
    {
        _logger = logger;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            await Task.Delay(TimeSpan.FromSeconds(30), stoppingToken);
            // check for updates
            _logger.LogInformation("Checking for updates...");
        }
    }
}